import { Controller, Post, Body } from '@nestjs/common';
import { TimerService } from './timer.service';
import { ApiTags, ApiOperation, ApiBody } from '@nestjs/swagger';
import { CreateTimerDto } from './dto/create-timer.dto';
import { Public } from 'src/common/public.decorator';
@ApiTags('定时器')
@Controller('timer')
export class TimerController {
  constructor(private readonly timerService: TimerService) {}

  @Post('start-timer')
  @Public()
  @ApiOperation({ summary: '启动定时器' })
  @ApiBody({ type: CreateTimerDto })
  startTimer(@Body() createTimerDto: CreateTimerDto) {
    return this.timerService.addCronJob(
      createTimerDto.name,
      '*/5 * * * * *',
      () => {
        console.log('定时器已启动');
      },
    );
  }

  @Post('stop-timer')
  @Public()
  @ApiOperation({ summary: '停止定时器' })
  stopTimer(@Body() createTimerDto: CreateTimerDto) {
    return this.timerService.stopCronJob(createTimerDto.name);
  }
}
